<?php require_once "menu.php"; ?>
    <style type="text/css">
        input, select {
            height: 18px;
            font-size: 12px;
        }
    </style>
<table width="100%" class="menubar" cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td class="menudottedline" width="40%"><div class="pathway"></div></td>
        <td class="menudottedline" align="right">
            <table cellpadding="0" cellspacing="0" border="0" id="toolbar">
                <tr height="60" valign="middle" align="center">
                    <td>
                        <a class="toolbar" id="savelink" href="javascript:;">
                        <?php echo $html->image('admin/save_f2.png', array('align' => 'middle', 'border' => 0)); ?><br/>Save
                        </a>
                    </td>
                    <td>
                        <a class="toolbar" id="backlink" href="javascript:;">
                        <?php echo $html->image('admin/restore_f2.png', array('align' => 'middle', 'border' => 0)); ?><br/>Back
                        </a>
                    </td>
                    <td>
                        <a class="toolbar" href="#">
                        <?php echo $html->image('admin/help_f2.png', array('align' => 'middle', 'border' => 0)); ?><br/>Help
                        </a>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<br>
<br>
<div align="center" class="centermain">
    <div class="main">

        <table class="adminheading">
            <tr>
                <th class="info" rowspan="2" nowrap><?php echo $page_title; ?></th>
            </tr>
        </table>

        <form id="userForm" name="userForm" method="post">
            <br/>
    		<div id="error" class="ui-widget">
    			<div class="ui-state-error ui-corner-all" style="background-color: #fef1ec; padding: 0 .7em;">
    				<p style="text-align: left;">
                        <span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
    				    <strong>Alert:</strong>
    				    <?php
    				     if (is_array($error)) {
    				        echo "<br/>";
    				        foreach($error as $err){
    		             ?>
    		            <label style="margin-left: 10px;"><?php echo $err; ?></label><br/>
    		            <?php
    				        }
    				     } else {
    		             ?>
    		            <label style="margin-left: 10px;"><?php echo $error; ?></label><br/>
    		            <?php
                         }
                         ?>
                    </p>
    			</div>
    		</div>
			<div id="msg" class="ui-widget">
				<div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;">
    				<p style="text-align: left;">
                        <span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
    				    <strong>Alert:</strong>
    				    <?php
    				     if (is_array($msg)) {
    				        foreach($msg as $err){
    		             ?>
    		            <label style="margin-left: 10px;"><?php echo $err; ?></label><br/>
    		            <?php
    				        }
    				     }
                         ?>
                    </p>
				</div>
			</div>
    		<br/>
            <table class="adminlist" cellpadding="20">
                <tr>
                    <th colspan="2">&nbsp;</th>
                </tr>
                <tr>
                    <td colspan="2" class="subheader">
                        <label>User Information</label>
                    </td>
                </tr>
                <tr>
                    <td id="input_label" style="width: 15%"><font color="red"><b>*</b></font>&nbsp;Lastname</td>
                    <td style="border: 1px dotted #ccc; background-color: #efefef;">
                        <input type="text" id="lastname" name="data[user_details][lname]" value="<?php echo $update['lname']; ?>" class="{required:true}" style="width: 350px;" />
                    </td>
                </tr>
                <tr>
                    <td id="input_label"><font color="red"><b>*</b></font>&nbsp;Firstname</td>
                    <td style="border: 1px dotted #ccc; background-color: #efefef;">
                        <input type="text" id="firstname" name="data[user_details][fname]" value="<?php echo $update['fname']; ?>" class="{required:true}" style="width: 350px;" />
                    </td>
                </tr>
                <tr>
                    <td id="input_label"><font color="red"><b>*</b></font>&nbsp;UID</td>
                    <td style="border: 1px dotted #ccc; background-color: #efefef;">
                        <input type="text" id="uname" name="data[user_details][uname]" value="<?php echo $update['uname']; ?>" class="{required:true, minlength: 5}" style="width: 350px;" />
                    </td>
                </tr>
                <tr>
                    <td id="input_label"><font color="red"><b>*</b></font>&nbsp;Privilege</td>
                    <td style="border: 1px dotted #ccc; background-color: #efefef;">
                        <?php echo $form->select('user_details.privilegeId', $privileges, $update['privilegeId'], array('id' => 'privilege', 'style' => 'width: 355px; height: 20px;', 'class' => '{required:true}')); ?>
                    </td>
                </tr>
                <tr>
                    <td id="input_label"><font color="red"><b>*</b></font>&nbsp;Email Address</td>
                    <td style="border: 1px dotted #ccc; background-color: #efefef;">
                        <input type="text" id="email_address" name="data[user_details][email_address]" value="<?php echo $update['email_address']; ?>" title="" class="{required:true,email:true}" style="width: 350px;" />
                    </td>
                </tr>
                <tr>
                    <td id="input_label"><font color="red"><b>*</b></font>&nbsp;Password</td>
                    <td style="border: 1px dotted #ccc; background-color: #efefef;">
                        <input type="password" id="token" name="data[user_details][token]" class="{required:true,minlength:5}" style="width: 350px;" />
                    </td>
                </tr>
                <tr>
                    <td id="input_label">&nbsp;Retype Password</td>
                    <td style="border: 1px dotted #ccc; background-color: #efefef;">
                        <input type="password" id="confirm_password" name="data[user_details][confirm_password]" class="{equalTo:'#token'}" style="width: 350px;" />
                    </td>
                </tr>
            </table>

            <input type="hidden" id="flag" name="data[flag]" />
        </form>

    </div>
</div>

<script type="text/javascript">
$(document).ready(function() {

    // validate form before submit
    $("#userForm").validate();

    $("#savelink").click(function () {
        var uid = '<?php echo $uid; ?>';
        $("#flag").val('add');
        if (uid == 0) {
            $("#userForm").attr('action', '<?php echo $html->url("/user/userdetails"); ?>');
        } else {
            $("#userForm").attr('action', '<?php echo $html->url("/user/userdetails/".$uid); ?>');
        }

        $("#userForm").submit();
    });

    $("#backlink").click(function () {
        window.location = "<?php echo $html->url('/user/usermgnt'); ?>";
    });

    var err = "<?php echo $error; ?>";
    $("#error").hide();
    $("#msg").hide();

    var error = '<?php echo $error; ?>';
    var msg = '<?php echo $msg; ?>';
    if (error && !msg) {
        $("#error").show();
        $("#msg").hide();
    }

    if (msg && !error) {
        $("#error").hide();
        $("#msg").show();
    }
});
</script>